<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
		<link rel="stylesheet" href="../css/sub-home.css" />
		<link rel="stylesheet" href="../css/aside-nav.css" />
		<style type="text/css">
			[v-cloak] {
				display: none !important;
			}
			
			.h-colum {
				padding: 0;
			}
			
			.mui-card {
				font-size: 14px;
				position: relative;
				overflow: hidden;
				background-color: #fff;
				background-clip: padding-box;
				box-shadow: 0 0 0 rgba(0, 0, 0, .3);
			}
			
			.mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-object {
				width: 100%;
				/*max-width: 65%; 备份版本针对是20180919*/
				max-width: 60%;
				height: auto;
			}
			
			.mui-card-header:after {
				height: 0px;
			}
			
			.mui-slider-title {
				color: #fff;
				background-color: rgba(0, 0, 0, 0.4);
			}
			/*	调整首页文字大小和图标间距*/
			
			.mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body {
				font-size: 14px;
				line-height: 15px;
				margin-top: 0px;
				font-family: Microsoft YaHei;
			}
		</style>
	</head>

	<body>

		<div id="pullrefresh">
			<div class="mui-content">
				<!--悬浮按钮操作-->
				<div class="aside-nav" id="aside-nav">
					<label for="" class="aside-menu" id="aside-menu" @click="switchMenu">	
					<!--<span class="mui-icon iconfont" v-bind:class="items.show ? 'icon-guanbi':'icon-caidan'"></span>-->
					<span class="mui-icon" v-bind:class="items.show ? 'mui-icon-closeempty':'iconfont icon-caidan'"></span>
				</label>
					<!--<div class="menu-item menu-first" id="menu-first" @click="switchHome" v-show="asideinfo.show">
						<span class="mui-icon iconfont icon-shouye"></span><label>返回首页</label>
					</div>-->
					<div v-if="items.children.menuSecond.flag == true" class="menu-item menu-second" id="menu-second" @click="switchBranch" v-show="items.show">
						<span class="mui-icon iconfont icon-zhibuhuodong"></span><label>本支部</label>
					</div>
					<div v-else class="menu-item menu-second" id="menu-second" @click="switchBranch" v-show="items.show">
						<span class="mui-icon iconfont icon-zuzhishenghuo"></span><label>全组织</label>
					</div>
				</div>
				<!--顶部导航-->
				<header class="mui-bar mui-bar-nav">
					<h1 class="mui-title">
						成都产业集团智慧党建系统
					</h1>
					<a class="mui-icon iconfont icon-sousuo mui-pull-right" style="margin-right: 5px;" id='btnsearch'></a>
					<!--<a class="mui-icon iconfont icon-qingdan mui-pull-right" href="#popover" id='btndepart'></a>-->
					<!--<a class="mui-icon iconfont icon-sousuo mui-pull-right" style="margin-right: 5px;" id='btnsearch'></a>-->
				</header>
				<!--滚动轮播-->
				<div id="slider" class="mui-slider" style="margin-top: 44px;">
					<div class="mui-slider-group">
						<div id="slider1" class="mui-slider">
							<div class="mui-slider-item">
								<a href="#">
									<img src="../images/32noimg.png">
								</a>
							</div>
						</div>
					</div>
				</div>
				<!--搜索区域
				<div class="mui-input-row" style="margin-bottom: -15px;" id="btnsearch">
					<div class="mui-input-row mui-search" style="margin: 10px 5px 0">
						<input type="search" class="mui-input-clear" placeholder="" data-input-clear="1" data-input-search="1">
						<span class="mui-placeholder"><span class="mui-icon mui-icon-search"></span></span>
					</div>
				</div>-->
				<!--首页栏目 1、宣传教育栏目 2、基层党建栏目 3、党风廉政栏目 4、工作推动栏目 5、企业文化栏目 last-h-colum-->
				<div id='page-colum' style="padding-bottom: 70px;">
					<div class="mui-row h-colum" v-for="item in items" v-cloak>
						<div class="mui-card">
							<div class="mui-card-header">{{item.name}}</div>
							<div class="mui-card-content" style="margin-top: 5px;">
								<ul class="mui-table-view mui-grid-view">
									<li class="mui-table-view-cell mui-col-xs-3" v-for="content in item.children">
										<a href="javascript:;" @click="showColom(content)">
											<img class="mui-media-object" v-bind:src="content.icon">
											<div class="mui-media-body">{{content.name}}</div>
										</a>
									</li>
								</ul>
							</div>
						</div>
					</div>
				</div>
				<!--滚动轮播模板-->
				<script id="sliderTmpl" type="text/html">
					<!--<div class="mui-slider-group mui-slider-loop">-->
					<div class="mui-slider-group">
						<!-- 额外增加的一个节点(循环轮播：第一个节点是最后一张轮播) -->
						<!--<div class="mui-slider-item mui-slider-item-duplicate">
						<a href="#">
							<img src="../images/1.jpeg">
							<p class="mui-slider-title">静静静静看这世界静静看这世界静静看这世界静静看这世界看这世界</p>
						</a>
					</div>-->

						{{each items as value index}}
						<div class="mui-slider-item">
							<!--<a href="javascript:;" data-id="{{value.id}}" onclick="javascript:showDetail({{value.id}},'')">-->
							<a href="javascript:;" data-id="{{value.id}}">
								{{if value.image!=''&&value.image!=null}}
								<img src='{{value.image}}' /> {{else}}
								<img src='../images/32noimg.png' /> {{/if}}
								<p class="mui-slider-title">{{value.title}}</p>
							</a>
						</div>
						{{/each}}
						<!-- 额外增加的一个节点(循环轮播：最后一个节点是第一张轮播) -->
						<!--<div class="mui-slider-item mui-slider-item-duplicate">
						<a href="#">
							<img src="../images/1.jpeg">
							<p class="mui-slider-title">幸福就是可以一起睡觉</p>
						</a>
					</div>-->
					</div>
				</script>
			</div>
		</div>
	</body>

</html>
<script type="text/javascript" src="../js/mui.min.js"></script>
<script type="text/javascript" src="../js/config.js"></script>
<script type="text/javascript" src="../js/template.js"></script>
<script type="text/javascript" src="../js/vue.min.js"></script>
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/jquery-2.1.0.js"></script>
<script type="text/javascript" src="../js/localStorage.js"></script>
<script type="text/javascript" src="../js/organization.js"></script>
<script type="text/javascript">
	var asidevm;
	var pageid;
	var asideinfo; // 快捷导航组织信息

	mui.init({
		swipeBack: true, //启用右滑关闭功能
		pullRefresh: {
			container: '#pullrefresh',
			down: {
				style: 'circle',
				height: 50, //可选,默认50.触发下拉刷新拖动距离,
				contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
				contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
				contentrefresh: "正在刷新...", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容

				style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
				color: '#2BD009', //可选，默认“#2BD009” 下拉刷新控件颜色

				range: '100px', //可选 默认100px,控件可下拉拖拽的范围
				offset: '0px', //可选 默认0px,下拉刷新控件的起始位置				
				callback: pulldownRefresh
			}
		}
	});

	function initSlider() {
		var gallery = mui("#slider");
		gallery.slider({
			interval: 3000
		});
	};

	function renderCms(result) {
		var strDom = template('sliderTmpl', {
			items: result
		});
		mui('#slider')[0].innerHTML = strDom;
		initSlider();

	}

	asideinfo = localStorageFunc.get("asideinfo") || localStorageFunc.set('asideinfo', asidenavigation);

	//	初始化渲染快捷导航
	asidevm = new Vue({
		el: "#aside-nav",
		data: {
			items: asideinfo,
		},
		methods: {
			//	快捷菜单切换
			switchMenu: function() {
				this.items.show = !this.items.show;
				setLocalinfo();
			},
			//	返回到主页
			switchHome: function() {
				this.items.show = false;
				if(pageid == '/html/sub-home.html') {
					return;
				}
				setLocalinfo();
			},
			// 支部和组织切换
			switchBranch: function() {
				this.items.children.menuSecond.flag = !this.items.children.menuSecond.flag;
				this.items.show = false;
				setLocalinfo();
			}
		}
	})

	//	初始化渲染DOM
	new Vue({
		el: "#page-colum",
		data: {
			items: organizationdata
		},
		methods: {
			//	查看二级栏目详情
			showColom: function(val) {
				switch(val.type) {
					case 'column':
						showOpen(val, 0);
						break;
					case 'workcircle':
						showOpen(val, 1);
						break;
					default:
						if(mui.os.ios) {
							showIOSOpen(val.name);
							return;
						}
						mui.toast(val.name + '模块开发中');
						break;
				}
			}
		}
	});

	//	资讯关键字搜索
	mui('body').on('tap', '#btnsearch', function() {
		mui.openWindow({
			url: '/html/home-search.html',
			id: 'home-search',
			createNew: false,
			show: {
				autoShow: true,
				aniShow: 'slide-in-right',
				duration: 300
			},
			waiting: {
				autoShow: false,
				title: '正在加载...'
			}
		})
	});

	mui.plusReady(function() {

		// 状态栏变色
		plus.navigator.setStatusBarStyle('light');
		plus.navigator.setStatusBarBackground('#e51c23');

		pageid = plus.webview.currentWebview().id;

		//	获取本地应用资源版本号
		plus.runtime.getProperty(plus.runtime.appid, function(info) {
			var appVer = info.version;
			//console.log('appVer:' + appVer);
			//var mtype = mui.os.android == true ? '1' : '2'; //plus.os.name 1,android 2,ios
			//var mtype = 'android';
			ctdj.tools.checkAppVersion(plus.os.name, appVer, function(r) {
				if(r.success) {
					if(r.result != null) {
						console.log('r' + JSON.stringify(r.result));
						var appPath = ctdj.tools.handelImageFullUrl(r.result.appUrl);
						mui.confirm('如无法自动更新,请到手机应用商城手动更新', '版本更新 v' + r.result.version + '版', ['暂不升级', '立即升级'], function(e) {
							if(e.index == 1) {
								console.log(plus.os.name);
								switch(plus.os.name) {
									case 'Android':
										createDownload(appPath);
										break;
									case 'iOS':
										//mui.toast('下载IOS版本');	
										window.location.href = 'https://appstoreconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app/1434252611';
										break;
									default:
										break;
								}
							}
							//}, 'div');
						});
					}
				} else {
					mui.toast(r.error);
				}
			})
			return;
			if(mui.os.android) {
				ctdj.tools.checkAppVersion(mtype, appVer, function(r) {
					if(r.success) {
						if(r.result != null) {
							console.log('r' + JSON.stringify(r.result));
							var appPath = ctdj.tools.handelImageFullUrl(r.result.appUrl);
							mui.confirm('如无法自动更新,请到手机应用商城手动更新', '版本更新 v' + r.result.version + '版', ['暂不升级', '立即升级'], function(e) {
								if(e.index == 1) {
									console.log(plus.os.name);
									switch(plus.os.name) {
										case 'Android':
											createDownload(appPath);
											break;
										case 'iOS':
											//mui.toast('下载IOS版本');	
											window.location.href = 'https://itunes.apple.com/cn/app/%E6%88%90%E9%83%BD%E4%BA%A7%E4%B8%9A%E5%85%9A%E5%BB%BA/id1434252611?mt=8';
											break;
										default:
											break;
									}
								}
								//}, 'div');
							});
						}
					} else {
						mui.toast(r.error);
					}
				})
			}
		});

		function createDownload(path) {
			//判断文件是否已经下载
			plus.io.resolveLocalFileSystemURL(
				'_downloads/update/',

				function(entry) {
					//	成功时回调：删除已存在的文档
					entry.removeRecursively(function() {
						//mui.toast('删除成功');
						updateAPP(path);
					});
				},
				function(e) {
					updateAPP(path);
				}

			);
		};

		//	更新新版本APP
		function updateAPP(path) {
			var waiting;
			waiting = plus.nativeUI.showWaiting("数据加载中,请耐心等待...");
			var dtask = plus.downloader.createDownload(path, {
				filename: "_downloads/update/"
			}, function(d, status) { //回调完成
				console.log('444下载完成');
			});

			dtask.addEventListener("statechanged", function(task, status) {
				switch(task.state) {
					case 0:
						console.log(new Date().toLocaleTimeString());
						console.log('数据加载中,请耐心等待...');
						break;
					case 1: // 开始
						console.log("开始下载...");
						break;
					case 2: // 已连接到服务器
						console.log("链接到服务器...");
						break;
					case 3: // 已接收到数据

						var percent = task.downloadedSize / task.totalSize * 100;
						waiting.setTitle("已下载... " + parseInt(percent) + "%");

						break;
					case 4: // 下载完成
						//mui.toast( "下载完成！");
						waiting.close();
						installApp(task.filename); // 安装wgt包
						break;
				}
			});

			dtask.start();
		}

		//	安装新版本APP
		function installApp(path) {
			plus.nativeUI.showWaiting("APP安装中...");
			plus.runtime.install(path, {
				force: false
			}, function() {
				plus.nativeUI.closeWaiting();
				console.log("APP安装成功！");
				plus.nativeUI.alert("应用资源更新完成！", function() {
					plus.runtime.restart();
				});
			}, function(e) {
				plus.nativeUI.closeWaiting();
				console.log('e:' + JSON.stringify(e));
				console.log(JSON.stringify(e)); //这里！e一直为null，path路径为_downloads/apk/10.apk
				mui.toast('安装失败');
			});
		}

		getCarousel();

	});

	//	获取滚动轮播数据
	function getCarousel() {

		// 绑定通知公告
		ctdj.cms.getCommendatory(function(r) {
			if(r.success) {
				if(r.result.length > 0) {
					for(var i = 0; i < r.result.length; i++) {
						if(r.result[i].image != '') { //设置相对路径
							r.result[i].image = ctdj.tools.handelImageFullUrl(r.result[i].image);
						}
					}
					renderCms(r.result);
				} else {
					mui('#slider')[0].innerHTML = '';
				}
			}
		});
	}

	//	设置本地存储
	function setLocalinfo() {
		//更新缓存数据
		localStorageFunc.set('asideinfo', asidevm.items);
	}

	function showDetail(detailid, columname) {
		if(asidevm.show) {
			asidevm.show = false;
			localStorageFunc.set('asideinfo', asideinfo);
		}

		mui.openWindow({
			url: '/html/home-detail.html',
			id: 'home-detail',
			createNew: false,
			extras: {
				'detailid': detailid,
				'columname': columname
			},
			show: {
				autoShow: true,
				aniShow: 'slide-in-right',
				duration: 300
			},
			waiting: {
				autoShow: false,
				title: '正在加载...'
			}
		})
	}

	//	打开资讯列表窗口
	function showIOSOpen(val) {
		if(val == '') return;
		mui.openWindow({
			url: '/html/home-list-other.html',
			id: 'home-list-other',
			createNew: false,
			extras: {
				'pinfo': val
			},
			show: {
				autoShow: true,
				aniShow: 'slide-in-right',
				duration: 300
			},
			waiting: {
				autoShow: false,
				title: '正在加载...'
			}
		})
	}

	//	更新点击推荐图多次点击无效bug
	mui('body').on('tap', '#slider .mui-slider-item a', function() {
		var dataid = this.getAttribute('data-id');
		//console.log('dataid=' + dataid);
		showDetail(dataid, '');

	});

	//	打开资讯列表窗口
	function showOpen(val, type) {
		if(val != '' && type != '') return;
		if(asidevm.show) {
			asidevm.show = false;
			setLocalinfo();
		}
		var targetId, tagetUrl;

		if(type == 0) {
			tagetUrl = '/html/home-list-zx.html';
			targetId = 'home-list-zx';
		} else {
			tagetUrl = '/html/home-list-cir.html';
			targetId = 'home-list-cir';
		}

		mui.openWindow({
			url: tagetUrl,
			id: targetId,
			createNew: false,
			extras: {
				'pinfo': val,
				'columid': val.id
			},
			show: {
				autoShow: true,
				aniShow: 'slide-in-right',
				duration: 300
			},
			waiting: {
				autoShow: false,
				title: '正在加载...'
			}
		})
	}

	function pulldownRefresh() {
		setTimeout(function() {
			getCarousel();
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
		}, 500);
	};

	window.addEventListener("myfresh", function(e) {
		setTimeout(function() {
			pulldownRefresh();
		}, 1000);
	});

	//	刷新当前界面。重置快捷导航数据
	window.addEventListener("updateNavbar", function(e) {
		asidevm.items = localStorageFunc.get("asideinfo");
	});
</script>